Lib,
Rlib,
Dylib,
- RustcMacro,
+ ProcMacro,
Other(String),
}
"lib" => LibKind::Lib,
"rlib" => LibKind::Rlib,
"dylib" => LibKind::Dylib,
- "rustc-macro" => LibKind::RustcMacro,
+ "procc-macro" => LibKind::ProcMacro,
s => LibKind::Other(s.to_string()),
}
}
LibKind::Lib => "lib",
LibKind::Rlib => "rlib",
LibKind::Dylib => "dylib",
- LibKind::RustcMacro => "rustc-macro",
+ LibKind::ProcMacro => "proc-macro",
LibKind::Other(ref s) => s,
}
}
LibKind::Lib |
LibKind::Rlib |
LibKind::Dylib |
- LibKind::RustcMacro => true,
+ LibKind::ProcMacro => true,
LibKind::Other(..) => false,
}
}
bench: Option<bool>,
doc: Option<bool>,
plugin: Option<bool>,
- rustc_macro: Option<bool>,
+ proc_macro: Option<bool>,
harness: Option<bool>,
}
bench: None,
doc: None,
plugin: None,
- rustc_macro: None,
+ proc_macro: None,
harness: None,
}
}
fn validate_crate_type(&self) -> CargoResult<()> {
// Per the Macros 1.1 RFC:
//
- // > Initially if a crate is compiled with the rustc-macro crate type
+ // > Initially if a crate is compiled with the proc-macro crate type
// > (and possibly others) it will forbid exporting any items in the
- // > crate other than those functions tagged #[rustc_macro_derive] and
+ // > crate other than those functions tagged #[proc_macro_derive] and
// > those functions must also be placed at the crate root.
//
// A plugin requires exporting plugin_registrar so a crate cannot be
// both at once.
- if self.plugin == Some(true) && self.rustc_macro == Some(true) {
- Err(human("lib.plugin and lib.rustc-macro cannot both be true".to_string()))
+ if self.plugin == Some(true) && self.proc_macro == Some(true) {
+ Err(human("lib.plugin and lib.proc-macro cannot both be true".to_string()))
} else {
Ok(())
}
.set_doctest(toml.doctest.unwrap_or(t2.doctested()))
.set_benched(toml.bench.unwrap_or(t2.benched()))
.set_harness(toml.harness.unwrap_or(t2.harness()))
- .set_for_host(match (toml.plugin, toml.rustc_macro) {
+ .set_for_host(match (toml.plugin, toml.proc_macro) {
(None, None) => t2.for_host(),
(Some(true), _) | (_, Some(true)) => true,
(Some(false), _) | (_, Some(false)) => false,
Some(kinds) => kinds.iter().map(|s| LibKind::from_str(s)).collect(),
None => {
vec![ if l.plugin == Some(true) {LibKind::Dylib}
- else if l.rustc_macro == Some(true) {LibKind::RustcMacro}
+ else if l.proc_macro == Some(true) {LibKind::ProcMacro}
else {LibKind::Lib} ]
}
};
# If the target is meant to be a "macros 1.1" procedural macro, this field must
# be set to true.
-rustc-macro = false
+proc-macro = false
# If set to false, `cargo test` will omit the `--test` flag to rustc, which
# stops it from generating a test harness. This is useful when the binary being
```
The available options are `dylib`, `rlib`, `staticlib`, `cdylib`, and
-`rustc-macro`. You should only use this option in a project. Cargo will always
+`proc-macro`. You should only use this option in a project. Cargo will always
compile packages (dependencies) based on the requirements of the project that
includes them.
-You can read more about the different crate types in the
+You can read more about the different crate types in the
[Rust Reference Manual](https://doc.rust-lang.org/reference.html#linkage)
# The `[replace]` Section
--- /dev/null
+extern crate cargotest;
+extern crate hamcrest;
+
+use cargotest::is_nightly;
+use cargotest::support::{project, execs};
+use hamcrest::assert_that;
+
+#[test]
+#[ignore]
+fn noop() {
+ if !is_nightly() {
+ return;
+ }
+
+ let client = project("client")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "client"
+ version = "0.0.1"
+ authors = []
+
+ [dependencies.noop]
+ path = "../noop"
+ "#)
+ .file("src/main.rs", r#"
+ #![feature(proc_macro)]
+
+ #[macro_use]
+ extern crate noop;
+
+ #[derive(Noop)]
+ struct X;
+
+ fn main() {}
+ "#);
+ let noop = project("noop")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "noop"
+ version = "0.0.1"
+ authors = []
+
+ [lib]
+ proc-macro = true
+ "#)
+ .file("src/lib.rs", r#"
+ #![feature(proc_macro, proc_macro_lib)]
+
+ extern crate proc_macro;
+ use proc_macro::TokenStream;
+
+ #[proc_macro_derive(Noop)]
+ pub fn noop(input: TokenStream) -> TokenStream {
+ input
+ }
+ "#);
+ noop.build();
+
+ assert_that(client.cargo_process("build"),
+ execs().with_status(0));
+ assert_that(client.cargo("build"),
+ execs().with_status(0));
+}
+
+#[test]
+#[ignore]
+fn impl_and_derive() {
+ if !is_nightly() {
+ return;
+ }
+
+ let client = project("client")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "client"
+ version = "0.0.1"
+ authors = []
+
+ [dependencies.transmogrify]
+ path = "../transmogrify"
+ "#)
+ .file("src/main.rs", r#"
+ #![feature(proc_macro)]
+
+ #[macro_use]
+ extern crate transmogrify;
+
+ trait ImplByTransmogrify {
+ fn impl_by_transmogrify(&self) -> bool;
+ }
+
+ #[derive(Transmogrify)]
+ struct X;
+
+ fn main() {
+ let x = X::new();
+ assert!(x.impl_by_transmogrify());
+ println!("{:?}", x);
+ }
+ "#);
+ let transmogrify = project("transmogrify")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "transmogrify"
+ version = "0.0.1"
+ authors = []
+
+ [lib]
+ proc-macro = true
+ "#)
+ .file("src/lib.rs", r#"
+ #![feature(proc_macro, proc_macro_lib)]
+
+ extern crate proc_macro;
+ use proc_macro::TokenStream;
+
+ #[proc_macro_derive(Transmogrify)]
+ #[doc(hidden)]
+ pub fn transmogrify(input: TokenStream) -> TokenStream {
+ assert_eq!(input.to_string(), "struct X;\n");
+
+ "
+ impl X {
+ fn new() -> Self {
+ X { success: true }
+ }
+ }
+
+ impl ImplByTransmogrify for X {
+ fn impl_by_transmogrify(&self) -> bool {
+ true
+ }
+ }
+
+ #[derive(Debug)]
+ struct X {
+ success: bool,
+ }
+ ".parse().unwrap()
+ }
+ "#);
+ transmogrify.build();
+
+ assert_that(client.cargo_process("build"),
+ execs().with_status(0));
+ assert_that(client.cargo("run"),
+ execs().with_status(0).with_stdout("X { success: true }"));
+}
+
+#[test]
+#[ignore]
+fn plugin_and_proc_macro() {
+ if !is_nightly() {
+ return;
+ }
+
+ let questionable = project("questionable")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "questionable"
+ version = "0.0.1"
+ authors = []
+
+ [lib]
+ plugin = true
+ proc-macro = true
+ "#)
+ .file("src/lib.rs", r#"
+ #![feature(plugin_registrar, rustc_private)]
+ #![feature(proc_macro, proc_macro_lib)]
+
+ extern crate rustc_plugin;
+ use rustc_plugin::Registry;
+
+ extern crate proc_macro;
+ use proc_macro::TokenStream;
+
+ #[plugin_registrar]
+ pub fn plugin_registrar(reg: &mut Registry) {}
+
+ #[proc_macro_derive(Questionable)]
+ pub fn questionable(input: TokenStream) -> TokenStream {
+ input
+ }
+ "#);
+
+ let msg = " lib.plugin and lib.proc-macro cannot both be true";
+ assert_that(questionable.cargo_process("build"),
+ execs().with_status(101).with_stderr_contains(msg));
+}
+++ /dev/null
-extern crate cargotest;
-extern crate hamcrest;
-
-use cargotest::is_nightly;
-use cargotest::support::{project, execs};
-use hamcrest::assert_that;
-
-#[test]
-#[ignore]
-fn noop() {
- if !is_nightly() {
- return;
- }
-
- let client = project("client")
- .file("Cargo.toml", r#"
- [package]
- name = "client"
- version = "0.0.1"
- authors = []
-
- [dependencies.noop]
- path = "../noop"
- "#)
- .file("src/main.rs", r#"
- #![feature(rustc_macro)]
-
- #[macro_use]
- extern crate noop;
-
- #[derive(Noop)]
- struct X;
-
- fn main() {}
- "#);
- let noop = project("noop")
- .file("Cargo.toml", r#"
- [package]
- name = "noop"
- version = "0.0.1"
- authors = []
-
- [lib]
- rustc-macro = true
- "#)
- .file("src/lib.rs", r#"
- #![feature(rustc_macro, rustc_macro_lib)]
-
- extern crate rustc_macro;
- use rustc_macro::TokenStream;
-
- #[rustc_macro_derive(Noop)]
- pub fn noop(input: TokenStream) -> TokenStream {
- input
- }
- "#);
- noop.build();
-
- assert_that(client.cargo_process("build"),
- execs().with_status(0));
- assert_that(client.cargo("build"),
- execs().with_status(0));
-}
-
-#[test]
-#[ignore]
-fn impl_and_derive() {
- if !is_nightly() {
- return;
- }
-
- let client = project("client")
- .file("Cargo.toml", r#"
- [package]
- name = "client"
- version = "0.0.1"
- authors = []
-
- [dependencies.transmogrify]
- path = "../transmogrify"
- "#)
- .file("src/main.rs", r#"
- #![feature(rustc_macro)]
-
- #[macro_use]
- extern crate transmogrify;
-
- trait ImplByTransmogrify {
- fn impl_by_transmogrify(&self) -> bool;
- }
-
- #[derive(Transmogrify)]
- struct X;
-
- fn main() {
- let x = X::new();
- assert!(x.impl_by_transmogrify());
- println!("{:?}", x);
- }
- "#);
- let transmogrify = project("transmogrify")
- .file("Cargo.toml", r#"
- [package]
- name = "transmogrify"
- version = "0.0.1"
- authors = []
-
- [lib]
- rustc-macro = true
- "#)
- .file("src/lib.rs", r#"
- #![feature(rustc_macro, rustc_macro_lib)]
-
- extern crate rustc_macro;
- use rustc_macro::TokenStream;
-
- #[rustc_macro_derive(Transmogrify)]
- #[doc(hidden)]
- pub fn transmogrify(input: TokenStream) -> TokenStream {
- assert_eq!(input.to_string(), "struct X;\n");
-
- "
- impl X {
- fn new() -> Self {
- X { success: true }
- }
- }
-
- impl ImplByTransmogrify for X {
- fn impl_by_transmogrify(&self) -> bool {
- true
- }
- }
-
- #[derive(Debug)]
- struct X {
- success: bool,
- }
- ".parse().unwrap()
- }
- "#);
- transmogrify.build();
-
- assert_that(client.cargo_process("build"),
- execs().with_status(0));
- assert_that(client.cargo("run"),
- execs().with_status(0).with_stdout("X { success: true }"));
-}
-
-#[test]
-#[ignore]
-fn plugin_and_rustc_macro() {
- if !is_nightly() {
- return;
- }
-
- let questionable = project("questionable")
- .file("Cargo.toml", r#"
- [package]
- name = "questionable"
- version = "0.0.1"
- authors = []
-
- [lib]
- plugin = true
- rustc-macro = true
- "#)
- .file("src/lib.rs", r#"
- #![feature(plugin_registrar, rustc_private)]
- #![feature(rustc_macro, rustc_macro_lib)]
-
- extern crate rustc_plugin;
- use rustc_plugin::Registry;
-
- extern crate rustc_macro;
- use rustc_macro::TokenStream;
-
- #[plugin_registrar]
- pub fn plugin_registrar(reg: &mut Registry) {}
-
- #[rustc_macro_derive(Questionable)]
- pub fn questionable(input: TokenStream) -> TokenStream {
- input
- }
- "#);
-
- let msg = " lib.plugin and lib.rustc-macro cannot both be true";
- assert_that(questionable.cargo_process("build"),
- execs().with_status(101).with_stderr_contains(msg));
-}